package com.shenzhen.group.common.game;

import com.shenzhen.group.common.entity.CardGroupBase;
import com.shenzhen.group.common.entity.HandCardGroupBase;
import com.shenzhen.group.common.player.Player;
import com.shenzhen.group.common.strategy.InvestStrategy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 押钱游戏抽象模板类
 * 模板方法模式
 * @author tooStronger
 * @date 2021/9/20
 */
public abstract class InvestGameTemplate {

    protected List<Position> positions;
    protected List<Player> players;
    protected CardGroupBase cardGroupBase;

    protected List<HandCardGroupBase> handCardGroupBases;

    protected int number = 1;

    protected Map<Long, InvestStrategy> strategyMap = new HashMap<>();

    /**
     * 坐位子
     */
    public abstract void init();

    public void process() {
        // 坐位子
        init();

        // 赋值给player
        this.players = positions.stream().map(Position::getPlayer).collect(Collectors.toList());

        // 拿牌组
        initCardGroupBase();

        int i = 0;
        while (i < number) {
            // 洗牌（可以不洗）+选庄家
            initShuffle();
            // 押钱
            initDet();
            // 发牌
            initLicensing();
            // 结算
            settlement();
            System.out.println("--------------------------------------------------------------------------------------------------------------------------------");
            System.out.println("--------------------------------------------------------------------------------------------------------------------------------");
            i++;
        }

    }


    /**
     * 结算
     */
    protected abstract void settlement();


    /**
     * 初始化玩家手中的牌
     * <pre>
     *   1.洗牌，选庄家
     * </pre>
     */
    protected abstract void initShuffle();

    /**
     * 发牌
     */
    protected abstract void initLicensing();

    /**
     * 初始化赌注
     * 押钱
     */
    protected abstract void initDet();

    /**
     * 初始化牌组
     * <pre>
     *     1. 初始化牌组
     * </pre>
     *
     */
    protected abstract void initCardGroupBase();

}
